import Message from "element-ui/packages/message/src/main";
import {exportGraphXmlAPI} from "../../api/outdateApi/centerBench";

function downloadFile(content, filename) {
    let a = document.createElement("a");
    let blob = new Blob([content]);
    let url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
}

const centerBench = {
    state: {},
    mutations: {},
    actions: {
        // importGraph: async ({commit}, graphName, file) => {
        //     //导入图谱
        //     let res = await importGraphAPI(graphName, file);
        //     if (res) {
        //         Message({
        //             message: '导入成功',
        //             type: 'success'
        //         });
        //     } else {
        //         Message({
        //             message: '导入失败',
        //             type: 'error'
        //         });
        //     }
        // },
        exportGraphXml: async ({commit}, xmlName) => {
            // 导出xml
            let xmlData = await exportGraphXmlAPI(xmlName);
            xmlName = xmlName + ".xml";
            if (xmlData) {
                downloadFile(xmlData, xmlName);
            } else {
                Message({
                    message: "导出失败",
                    type: "error",
                });
            }
        }
    }
};

export default centerBench;